#!/usr/bin/node

// this app used to monitor system available by writing pulse signal to hardware watchdog
// also it will be used to a self-upgrade app, it use cron task schedule to run 'git pull'
// we need to use pm2 watch feature to restart my app when there is any file has been changed.

const fs = require('fs')
const CronJob = require('cron').CronJob;


fs.open('/dev/watchdog', 'w', (err, fd) => {
  if (err) {
    console.error('failed to open watchdog')
  } else {
    setInterval(() => {
      // console.info('writing to watchdog')
      fs.writeSync(fd, 's')
    }, 1000)
  }
})

new CronJob('* * * * * *', () => {
  // console.log('You will see this message every second')
}, null, true, 'Asia/Shanghai')
